<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class PayRoll extends CI_Controller {
 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
   $this->load->helper('date');
   $this->load->library('my_salary');
   $this->load->library('my_time');
 }
 function index(){	
	$roles=$this->session->userdata('roles');		
    if($roles==0||$roles==1)
         { 
		 if (!empty($_POST)){
		 	$FromDate=$this->input->post('FromDate');
			$ToDate=$this->input->post('ToDate');
			$result=$this->muser->getStaffID();
			foreach ($result as $row) {
				$this->my_salary->makeSalary($row->Staff_ID,$FromDate,$ToDate);			
			}
			$result=$this->muser->getSalary($FromDate,$ToDate);
			$data['FromDate']=$FromDate;
			$data['ToDate']=$ToDate;
            $data['result']=$result;
			$this->load->view('_header');
      	    $this->load->view('payRoll/payRoll_view',$data); 
            $this->load->view('_footer');
		 }else{
		 	$this->load->view('_header');
      	    $this->load->view('payRoll/payRoll_view'); 
            $this->load->view('_footer');
		 } 			    
            
      }
     else
         {
             $data['ban_roles']="You haven't this role";
             $this->load->view('_header',$data);
             $this->load->view('notAllowRole');
             $this->load->view('_footer');
         }
			 
	}  
 	 function edit1 ()
			 {
			 	$DT=array(
									"Salary_ID"=>$this->input->post('Salary_ID'),
									"Staff_ID"=>$this->input->post('Staff_ID'),
									"FullName"=>$this->input->post('FullName'),
									"FromDate"=>$this->input->post('FromDate'),
									"ToDate"=>$this->input->post('ToDate'),
									"BasicSalary"=>$this->input->post('BasicSalary'),
									"ActSalary"=>$this->input->post('ActSalary'),
									"WorkingDay"=>$this->input->post('WorkingDay'),
									"PIT"=>$this->input->post('TotalAllowance'),
									"PerformanceBonus"=>$this->input->post('PerformanceBonus'),
									"ComDeduction"=>$this->input->post('ComDeduction'),
									"E_SI"=>$this->input->post('E_SI'),
									"E_HI"=>$this->input->post('E_HI'),
									"E_UI"=>$this->input->post('E_UI'),
									"E_SHU"=>$this->input->post('E_SHU'),
									"C_SI"=>$this->input->post('C_SI'),
									"C_HI"=>$this->input->post('C_HI'),
									"C_UI"=>$this->input->post('C_UI'),
									"C_SHU"=>$this->input->post('C_SHU'),
									"NoneTax"=>$this->input->post('NoneTax'),
									"PreTax"=>$this->input->post('PreTax'),	
									"PaySalary"=>$this->input->post('PaySalary'),
									"Total"=>$this->input->post('Total')									
															
							);
				$this->muser->updateData('Salary','Salary_ID',$DT['Salary_ID'],$DT);
				$data['error']='Edit successful!';	 	
				redirect('allSalary/index',$data);		
			 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('Salary','Salary_ID',$str);
	$data['result']=$result;	
 	$this->load->view('_header');
	$this->load->view('payRoll/editSalary_view',$data);	
	$this->load->view('_footer');
 }
 
}